package com.nineclock.system.easyexcel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.nineclock.system.service.SysCompanyUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.LifecycleState;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class ExcelMemberListener extends AnalysisEventListener<ExcelMember> {


   List<ExcelMember> excelMemberList= new ArrayList<ExcelMember>();

    private SysCompanyUserService sysCompanyUserService;

    public ExcelMemberListener(){

    }
    public ExcelMemberListener(SysCompanyUserService sysCompanyUserService){
        this.sysCompanyUserService=sysCompanyUserService;
    }

    @Override
    public void invoke(ExcelMember data, AnalysisContext context) {
       log.info("解析每一行的数据"+data);
       excelMemberList.add(data);
    }

    /**
     *解析Exel文件
     */

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        sysCompanyUserService.handleParsedData(excelMemberList);
    }
}
